<template>
    <div style="width:100%">
        <div class="panel-title">
            <h2>投资添加</h2>
        </div>
        <div class="panel-body">
            <fieldset class="pure-form pure-form-aligned">
                <div class="pure-control-group">
                    <label for="name">投资名称：</label>
                    <input v-model="iName" class="pure-input-1-3" type="text" />
                </div>
                <div class="pure-control-group">
                    <label for="name">投资总金额：</label>
                    <input v-model="iBudget" class="pure-input-1-3" type="Number" /> 万元
                </div>
                <div class="pure-control-group">
                    <label for="name">已投资金额：</label>
                    <input v-model="iReceive" class="pure-input-1-3" type="Number" />万元
                </div>
                <div class="pure-control-group">
                    <label for="name" style="width 40%">剩余金额：</label>
                    <input v-model="iResidue" class="pure-input-1-3" type="Number" style="width 60%" />万元
                </div>
                <div class="pure-control-group">
                    <label for="name">投资人数：</label>
                    <input v-model="iNumber" class="pure-input-1-3" type="Number" />
                </div>
                <div class="pure-controls">
                    <input class="pure-button pure-button-primary" type="button" value="提交" @click="AddInvest()" />
                </div>
            </fieldset>
        </div>
    </div>
</template>

<style src="../../../assets/DomCss/css/pure-nr-min.css"></style>
<style src="../../../assets/DomCss/css/main.css"></style>
<style src="../../../assets/DomCss/css/admin.css"></style>
<style src="../../../assets/DomCss/css/fontAwesome/font-awesome.css"></style>

<script lang="ts" setup>
import {ref} from "vue"
import axios from "axios"
import { useRouter } from 'vue-router'
let iName = ref("");
let iBudget = ref(0.1);
let iReceive = ref(0.1);
let iResidue = ref(0.1);
let iNumber = ref(1);
let router = useRouter();

function AddInvest(){
    if(iName.value==null || iName.value==""){
        alert('投资名称不能为空');
        return;
    }

    if(iBudget.value==null || iBudget.value==0){
        alert('投资总金额不能为空');
        return;
    }

    if(iReceive.value==null || iReceive.value==0){
        alert('已投金额不能为空');
        return;
    }

    if(iResidue.value==null || iResidue.value==0){
        alert('剩余金额不能为空');
        return;
    }

    if(iResidue.value==null || iResidue.value==0){
        alert('投资人数不能为空');
        return;
    }

    axios.post("https://localhost:44395/CreateInvest",{
        "I_Name":iName.value,
        "I_Budget":iBudget.value,
        "I_Receive":iReceive.value,
        "I_Residue":iResidue.value,
        "I_Number":iNumber.value
    })
    .then(function(res){
        console.log(res.data);
        if(res.data==null || res.data.length==0)
        {
            //添加失败
            alert('添加失败');
            return;
        }
        //添加成功
        alert("添加成功");
        //跳转页面
        router.push("")

    })
    .catch(function(err){
        console.log(err);
    });
}
</script>
